﻿using System;
using System.IO;
using Serialize.Library;

namespace Message.Library.Aliyun
{
    /// <summary>
    /// 创建工厂
    /// </summary>
    public class ConfigManager
    {

        /// <summary>
        /// 配置信息
        /// </summary>
        private static AliyunConfig _connectConfig;

        /// <summary>
        ///  Aliyun配置信息
        /// </summary>
        internal static AliyunConfig config => _connectConfig;

        static ConfigManager()
        {
            try
            {
                string rootDic = string.Empty;
                //相对路径
                //rootDic = Directory.GetCurrentDirectory();
                //rootDic = AppDomain.CurrentDomain.BaseDirectory;

                rootDic = AppContext.BaseDirectory;

                //获取当前程序bin目录路径(还未在Web环境下测试过)
                using (StreamReader sr = new StreamReader(Path.Combine(rootDic, "Config/aliyun.config.json")))
                {
                    _connectConfig = sr.ReadToEnd().JsonToObject<AliyunConfig>();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
